home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / memory / malloc.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  663b  |  41 lines

  1.  
  2. /*
  3.  *  MALLOC.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <clib/exec_protos.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <errno.h>
  17.  
  18. extern long *__MemList;
  19.  
  20. void *
  21. malloc(bytes)
  22. size_t bytes;
  23. {
  24.     long *ptr;
  25.  
  26.     if (bytes == 0)
  27.     return(NULL);
  28.  
  29.     ptr = AllocMem(bytes + 8, MEMF_PUBLIC);
  30.     if (ptr) {
  31.     ptr[0] = (long)__MemList;
  32.     __MemList = ptr;
  33.     ptr[1] = bytes + 8;
  34.     ptr += 2;
  35.     } else {
  36.     errno = ENOMEM;
  37.     }
  38.     return((void *)ptr);
  39. }
  40.  
  41.